package disenioPantallas.AltaAnimal;

import gestores.GestorErrores;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import disenioPantallas.elementos.EButton;
import disenioPantallas.elementos.ELabel;
import disenioPantallas.elementos.EPanel;
import disenioPantallas.elementos.ETextField;
import disenioPantallas.elementos.dialogGeneral;



public class DIngresarCaravana extends dialogGeneral {

	private static final long serialVersionUID = 1L;
	private JTextField txCaravana;
	private String caravana;
	
	public DIngresarCaravana() {
		setTitle("Ingresar Caravana");
		setMinimumSize(new Dimension(400, 150));
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
		
		Component verticalStrut = Box.createVerticalStrut(8);
		getContentPane().add(verticalStrut);
		
		JPanel panelPesaje = new EPanel();
		getContentPane().add(panelPesaje);
		panelPesaje.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JLabel lbCaravana = new ELabel("Caravana:");
		lbCaravana.setHorizontalAlignment(SwingConstants.CENTER);
		panelPesaje.add(lbCaravana);
		
		Component horizontalStrut = Box.createHorizontalStrut(20);
		panelPesaje.add(horizontalStrut);
		
		txCaravana = new ETextField();
		panelPesaje.add(txCaravana);
		
		JPanel panelCancelar = new EPanel();
		getContentPane().add(panelCancelar);
		
		JButton btnAceptar = new EButton("Aceptar");
		panelCancelar.add(btnAceptar);
		btnAceptar.addActionListener(new aceptarAction());
		
		JButton btnCancelar = new EButton("Cancelar");
		panelCancelar.add(btnCancelar);
		btnCancelar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				setCaravana(null);
				cerrarDialog();
			}
		});

	}

	public String getCaravana() {
		return caravana;
	}

	public void setCaravana(String caravana) {
		this.caravana = caravana;
	}
	
	private class aceptarAction extends AbstractAction{


		private static final long serialVersionUID = 1L;

		public void actionPerformed(ActionEvent e) {
			if(!txCaravana.getText().equals("")){
				setCaravana(txCaravana.getText());
				cerrarDialog();
			}
			else
				GestorErrores.getGestorErrores().mostrarCartelError("Ingrese una Caravana");
		}
		
	}
}